# 使用python:3.9-slim-bullseye作为基础镜像
FROM python:3.9-slim-bullseye

# 设置工作目录
WORKDIR /app

# 配置阿里云镜像源
RUN echo "deb https://mirrors.aliyun.com/debian/ bullseye main non-free contrib" > /etc/apt/sources.list && \
    echo "deb https://mirrors.aliyun.com/debian-security/ bullseye-security main" >> /etc/apt/sources.list && \
    echo "deb https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib" >> /etc/apt/sources.list

# 更新包列表并安装必要的构建工具
RUN apt-get update && \
    apt-get install -y gcc g++ build-essential && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# 配置pip使用阿里云镜像源，设置超时和重试
RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ && \
    pip config set global.trusted-host mirrors.aliyun.com && \
    pip config set global.timeout 300 && \
    pip config set global.retries 5

# 复制requirements.txt
COPY requirements.txt .

# 安装Python依赖（不升级pip）
RUN pip install --no-cache-dir -r requirements.txt

# 复制应用代码
COPY . .

# 暴露端口
EXPOSE 8000

# 启动命令
CMD ["python", "-m", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]